<?php


namespace App\Http\Controllers\Admin\System;


use App\Http\Controllers\Admin\BaseController;
use App\Repositories\System\GroupRepository;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;

class GroupController extends BaseController
{
    public function __construct()
    {
        $this->set('system/group');
    }

    function index()
    {
        return $this->view('index');
    }

    function pager(GroupRepository $rep, Request $request)
    {
        return $rep->adminPager($request->all());
    }


    /**
     * 权限
     * @param int $id
     * @param GroupRepository $repository
     * @return Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|mixed
     */
    public function permission_view(int $id, GroupRepository $repository)
    {
        $permissions = $repository->allPermissions($id)->data;
        return view('admin/system/group/permission', compact('permissions', 'id'))->with('baseRoute', $this->routePrefix . '/');
    }

    /**
     * @param GroupRepository $repository
     * @param Request $request
     * @return \App\Utils\Output
     */
    public function permission(GroupRepository $repository, Request $request)
    {
        return $repository->savePermission($request->post());
    }
}